Support has_many through associations with composite query_constraints #47452
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for
has_many :items, through: :association
associations defined with compositequery_constraints
The change is similar to other ones. Since
reflection.join_primary_key
andreflection.join_foreign_key
can both be Arrayshttps://github.com/rails/rails/blob/4085395f41f8c9c712f39ea6bec64ae6161bfbc9/activerecord/lib/active_record/reflection.rb#L512-L515
https://github.com/rails/rails/blob/4085395f41f8c9c712f39ea6bec64ae6161bfbc9/activerecord/lib/active_record/reflection.rb#L496-L499
next_chain_scope
should be ready to process them as arrays.Then we iterate over pairis of primary & foreign keys, building
Equality
arel nodes and joining them withAND
if we have more than oneeq
condition.For tests
Sharded
models were extended with theTag
models that is associated withBlogPost
throughblog_posts_tags
joining table